import { RepositoryBase } from "@repositories/repository.base";
import { OrderModel } from "@models/order.model";

class OrderRepository extends RepositoryBase<OrderModel> {
  async add(record: OrderModel): Promise<OrderModel> {
    record.id = record.createId();

    return super.add(record);
  }

  async update(newRecord: OrderModel): Promise<OrderModel> {
    const oldRecord = await this.findById(newRecord.id);
    return await super.update(oldRecord, newRecord);
  }

  async delete(record: OrderModel): Promise<void> {
    return await super.delete(record);
  }

  async getAll(): Promise<OrderModel[]> {
    return await super.find({});
  }

  async findById(id: string): Promise<OrderModel> {
    return await super.findOne({ id: id });
  }

  async findByProductId(productId: string): Promise<OrderModel[]> {
    return await super.find({ productId: productId });
  }
}

export { OrderRepository };
